package com.rd.teacher.jichao.day16;

import java.util.Scanner;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

// 三个线程分别打印 A，B，C，要求这三个线程一起运行，打印 n 次，
// 输出形如“ABCABCABC....”的字符串。
public class TestABC {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入打印的次数：");
        int count = scanner.nextInt();

        ExecutorService single = Executors.newSingleThreadExecutor();
        for (int i = 0; i < count; i++) {
            single.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.print("A");
                }
            });

            single.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.print("B");
                }
            });

            single.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.print("C");
                }
            });
        }
        single.shutdown();
    }
}
